package com.example.killer.shichatexiao;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.ArrayAdapter;
import android.widget.ImageView;

import com.example.killer.shichatexiao.ui.MyListView;
import com.example.killer.shichatexiao.util.Cheeses;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final MyListView mListView = (MyListView) findViewById(R.id.lv);
        //消除当滑动到边界的时候，如果再滑动，就会有一个边界就会有一个发光效果
        mListView.setOverScrollMode(View.OVER_SCROLL_NEVER);

        //加Header
        final View mHeader = View.inflate(MainActivity.this,R.layout.view_header,null);
        final ImageView imageView = (ImageView) mHeader.findViewById(R.id.iv);
        mListView.addHeaderView(mHeader);

        mHeader.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                //当布局填充完后此方法会被调用
                mListView.setParallaxImage(imageView);
                mHeader.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            }
        });

        //填充数据
        mListView.setAdapter(new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_list_item_1, Cheeses.NAMES));
    }
}
